import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import {resolve} from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
    resolve: {
        // 设置路径别名
        alias: {
            '@': resolve(__dirname, './src'),
            '*': resolve('')
        },
    },
    envDir: resolve(__dirname, 'env'),
    plugins: [
        vue(),
        AutoImport({
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [ElementPlusResolver()],
        }),
    ],
    css: {
        //  css预处理
        preprocessorOptions: {
            scss: {
                //  引入全局预定义变量
                additionalData: `@import "./src/assets/style/variables.scss";`,
            }
        }
    },
    build: {
        rollupOptions: {
            input: {
                frontend: resolve(__dirname, 'src/packages/frontend/index.html'),
                manager: resolve(__dirname, 'src/packages/manager/index.html')
            },
            output: {
                chunkFileNames: 'js/[name]-[hash].js',
                entryFileNames: 'js/[name]-[hash].js',
                assetFileNames: '[ext]/[name]-[hash].[ext]',
            }
        }
    }
})
